<?php
/**
 * 【文章】接口控制器
 * 
 */
class articleAction extends apiAction {
	/**
	 * 知识库文章分类
	 */
	public function kb(){
		$data = array();
		$cate = D('ArticleCate')->where(array('pid'=>1))->select();
		foreach($cate as $row){
			$data[$row['id']] = array('cateId'=>$row['id'], 'name'=>$row['name']);
		}
		$this->ajaxReturn(200, L('success'), $data);
	}
	
	/**
	 * 机型信息
	 */
	public function model(){
		$list = D('article')->where(array('cateId'=>3))->select();
		$this->assign('list', $list);
		$this->display();
	}
	
	/**
	 * 学习园地
	 */
	public function study(){
		$list = D('article')->where(array('cateId'=>2))->select();
		$this->assign('list', $list);
		$this->display();
	}
	
	/**
	 * 列表
	 */
	public function index(){
		$page	= I('page', 1);		// 要显示第几页数据
		$num	= I('num', 20);		// 每页显示多少条数据
		$cateId	= I('cateId', 11);	// 分类 id (默认为知识库营销政策)
		
		$data = array();
		
		$articles = D('article')->where(array('cateId'=>$cateId,'status'=>1))->order('ordid')->limit($num)->page($page)->select();
		if($articles){
			foreach ($articles as $row){
				$data[$row['id']]['id']		= $row['id'];
				$data[$row['id']]['title']	= $row['title'];
				$data[$row['id']]['date']	= date('Y-m-d',$row['addTime']);
			}
			$this->ajaxReturn(200, L('success'), $data);
		}else{
			$this->ajaxReturn(300,  L('no_more'));
		}
	}
	
	/**
	 * 公告详情
	 */
	public function detail(){
		$id	= I('id');
		$article = D('article')->where(array('id'=>$id,'status'=>1))->find();
		//增加浏览量
		D('article')->where(array('id'=>$id,'status'=>1))->save(array('hits'=>array('exp','hits+1')));
		// 去除 style="white-space:nowrap;" 样式
		$article['info'] = str_replace('style="white-space:nowrap;"','', $article['info']);
		$this->assign('article',$article);
		$this->display();
	}
}
/* End of file articleAction.class.php */